# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=groff
pkgver=1.22.3
pkgrel=1
pkgdesc="GNU troff text-formatting system"
arch=('i686' 'x86_64')
url="https://www.gnu.org/software/groff/groff.html"
license=('GPL')
groups=('base-devel')
depends=('perl' 'gcc-libs')
makedepends=()
optdepends=()
source=(https://ftp.gnu.org/gnu/groff/groff-$pkgver.tar.gz{,.sig}
        site.tmac
        groff-1.22.2-msys2.patch
        0001-fix-mom-pdf-symlink.patch)
options=('!docs' '!emptydirs')
install=groff.install
sha256sums=('3a48a9d6c97750bfbd535feeb5be0111db6406ddb7bb79fc680809cda6d828a5'
            'SKIP'
            'af59ecde597ce9f8189368a7739279a5f8a391139fe048ef6b4e493ed46e5f5f'
            '10efa126651f4408ec391061b15a8810cc21dbb75449f7b7802400d8e6a2d26f'
            'd8d7d7a7146b1a83387213c552207c91d6c9aceb51943b99b19fb6125f8e171a')

prepare() {
  cd $srcdir/$pkgname-$pkgver

  patch -p2 -i $srcdir/0001-fix-mom-pdf-symlink.patch
  patch -p1 -i $srcdir/groff-1.22.2-msys2.patch

  autoreconf -fvi -I m4
}

build() {
  cd $srcdir/$pkgname-$pkgver
  ./configure --prefix=/usr
  make
}

check() {
  cd $srcdir/$pkgname-$pkgver
  make check
}

package() {
  cd $srcdir/$pkgname-$pkgver
  make DESTDIR=$pkgdir install

  rm -f $pkgdir/usr/lib/charset.alias

  # FS33760 - TERMCAP variables not followed
  # TODO: everyone is doing this - find out why upstream does not...
  cat $srcdir/site.tmac >> \
    $pkgdir/usr/share/groff/site-tmac/man.local
  cat $srcdir/site.tmac >> \
    $pkgdir/usr/share/groff/site-tmac/mdoc.local
}
